// pages/SCM/takePhotoRecord/takePhotoRecord.js
// pages/SCM/takePhoto/takePhoto.js
const app = getApp()
const util = require('../../../utils/util.js')
const lbbService = require('../../service/service.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    cardnumber: '',
    pageNum: 1,
    flag: true, //触底开关
    noShow: false,
    pageSize: 10,
    showPile:true,
    pileId:'',
    equId:'',
    clickChangeColorR:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      hospitalId: options.hospitalId ? options.hospitalId : '',
      pileId: options.pileCode ? options.pileCode : '',
      equId: options.equId ? options.equId : '',
      inspectId: options.inspectId?options.inspectId:''
    })
    that.getAxios()
  },
  toTakePhoto(e) {
    console.log(e, 'eeeeeeeeeee')
    if(e.currentTarget.dataset.pileId){
      wx.navigateTo({
        url: '../takePhoto/takePhoto?data=' + JSON.stringify(e.currentTarget.dataset.item),
      })
    }else {
      wx.navigateTo({
        url: '../takePhoto/takePhoto?data=' + JSON.stringify(e.currentTarget.dataset.item)
      })
    }
  },
  clickPile(){
    this.setData({
      showPile:true,
      clickChangeColorR:true
    })
  },
  clickEqu(){
    this.setData({
      showPile:false,
      clickChangeColorR:false
    })
  },
  getAxios() {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    lbbService.getInspectUploadPic({
      lbmId: that.data.hospitalId,
      pageNum: that.data.pageNum,
      pileId: that.data.pileId,
      equId: that.data.equId ? that.data.equId : '',
      pageSize: that.data.pageSize,
      inspectId: that.data.inspectId ? that.data.inspectId : '',
    }, function (res) {
      let dataList_Pile = res.data.filter((item)=>{ return item.pileId !=0})
      let dataList_Equ = res.data.filter((item)=>{ return item.equId != 0})
      console.log(dataList_Pile,dataList_Equ,'我丢丢对')
      console.log(res,'我丢丢对')
      that.setData({
        dataList: res.data,
        noShow: true,
        dataList_Pile : dataList_Pile,
        dataList_Equ : dataList_Equ
      })
      console.log(res)
      wx.hideLoading()
    })
  },
  getAxiosed() {
    var that = this;
    lbbService.getInspectUploadPic({
      lbmId: that.data.hospitalId,
      pageNum: that.data.pageNum,
      pileId: that.data.pileId,
      equId: that.data.equId ? that.data.equId : '',
      pageSize: that.data.pageSize,
      inspectId: that.data.inspectId ? that.data.inspectId : '',
    }, function (res) {
      console.log(res)
      that.setData({
        dataList: res.data,
        noShow: true
      })
      wx.hideLoading()
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;

    that.getAxiosed();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.flag) {
      that.setData({
        pageNum: that.data.pageNum + 1, //每次触发上拉事件，把searchPageNum+1  
      });
      that.getAxios();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})